﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using THSERP.BaseProvider;
using THSLib;
using THSERP.BusinessEntities;
namespace THSERP.Modules.TaxDec
{
    public partial class guiSelectTaxDec :THSERPScreen
    {
        public guiSelectTaxDec()
        {
            InitializeComponent();
            
        }

        private void guiSelectInvoice_Load(object sender, EventArgs e)
        {
            fld_dgcARTaxDeclarations.Screen = this;
            fld_dgcARTaxDeclarations.InitializeControl();
            fld_dteSearchFromARTaxDeclarationDate.Screen = this;
            fld_dteSearchToARTaxDeclarationDate.Screen = this;
            fld_dteSearchFromARTaxDeclarationDate.DateTime = THSApp.WorkingDate;
            fld_dteSearchToARTaxDeclarationDate.DateTime = THSApp.WorkingDate;
            DataSet ds = new GEVATsController().GetAllObjects();
            TaxDecEntities entity = (TaxDecEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            entity.ARTaxDeclarationsList.Invalidate(new DataSet());

        }

        private void fld_btnSearch_Click(object sender, EventArgs e)
        {
            String strQuery = String.Format("SELECT * FROM ARTaxDeclarations WHERE (CONVERT(VARCHAR(10), [ARTaxDeclarationDate], 112) >= CONVERT(VARCHAR(10),'{0}', 112)) AND (CONVERT(VARCHAR(10), [ARTaxDeclarationDate], 112) <= CONVERT(VARCHAR(10),'{1}', 112)) AND AAStatus='Alive' ", fld_dteSearchFromARTaxDeclarationDate.DateTime.ToString("yyyyMMdd"), fld_dteSearchToARTaxDeclarationDate.DateTime.ToString("yyyyMMdd"));
            DataSet ds = new ARTaxDeclarationsController().GetDataSet(strQuery);
            TaxDecEntities entity = (TaxDecEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            entity.ARTaxDeclarationsList.Invalidate(ds);
            BindingSource bds = new BindingSource();
            bds.DataSource = entity.ARTaxDeclarationsList;
            fld_dgcARTaxDeclarations.RefreshDataSource();
            fld_chkSelectAll.Checked = false;
        }

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
             TaxDecEntities entity = (TaxDecEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            //if (fld_lkeFK_GEVATID.EditValue == null)
            //{
            //    MessageBox.Show("Chưa chọn thuế!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}

            if (!entity.ARTaxDeclarationsList.Exists("AASelected", true))
            {
                MessageBox.Show("Chọn hóa đơn trước khi In !","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void fld_chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
             TaxDecEntities entity = (TaxDecEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            if (Convert.ToBoolean(fld_chkSelectAll.EditValue))
            {

                for (int i = 0; i < entity.ARTaxDeclarationsList.Count; i++)
                {
                     ((ARTaxDeclarationsInfo)entity.ARTaxDeclarationsList[i]).AASelected=true;
                    
                }
            }
            else
            {
                for (int i = 0; i < entity.ARTaxDeclarationsList.Count; i++)
                {
                    ((ARTaxDeclarationsInfo)entity.ARTaxDeclarationsList[i]).AASelected = false;
                }
            }
            
            fld_dgcARTaxDeclarations.Views[0].RefreshData();
        
        }
    }
}